package cn.zswltech.gruul.web.api.util;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * @author xuluquan
 * @date 2020-05-06 15:55
 */
@Component
public class EnvironmentUtil {

    @Autowired
    private Environment environment;

    /**
     * 获取boolean类型数据
     *
     * @param key
     * @return boolean
     * @author xuluquan
     * @date 2019-08-23 15:55
     */
    public boolean getBoolean(String key) {
        String switchOn = environment.getProperty(key);
        if (StringUtils.isBlank(switchOn)) {
            //默认返回false
            return false;
        }
        return Boolean.valueOf(switchOn);
    }

    /**
     * 获取数据
     *
     * @param key
     * @return boolean
     * @author xuluquan
     * @date 2019-08-23 15:55
     */
    public String getProperty(String key) {
        return environment.getProperty(key);
    }

    /**
     * 获取kafka开关
     *
     * @param
     * @return boolean true=打开kafka，false=关闭kafka
     * @author xuluquan
     * @date 2019-08-23 15:58
     */
    public boolean getKafkaSwitch() {
        return getBoolean("bifrost.kafka.switch");
    }


}
